package LeetCode.interview;

import com.sun.crypto.provider.RSACipher;

import util.LogUtils;

/*
 * 
 * 原题
 * Reverse digits of an integer. 
 * Example1: x = 123, return 321 
 * Example2: x = -123, return -321 
 * 题目大意
 * 输入一个整数对其进行翻转 
 * @Date 2017-09-12 15：39
 */
public class _007_Reverse_Integer {

	public int reverse(int n) {
		
		long temp = n;
		long result = 0;
		while (temp != 0) {
			result = result*10 + temp%10;
			temp = temp / 10;
		}
        // 溢出判断 
        if (result < Integer.MIN_VALUE || result > Integer.MAX_VALUE) {
            result = 0;
        }

        return (int) result;
	}

	public static void main(String[] args) {
		LogUtils.println("结果", new _007_Reverse_Integer().reverse(985));
	}

}
